# $Id: PKGBUILD 163804 2012-07-20 09:37:31Z ronald $
# Maintainer: Ronald van Haren <ronald.archlinux.org>
# Contributor: Keshav P R <(the.ridikulus.rat) (aatt) (gemmaeiil) (ddoott) (ccoomm)>

_grub_lua_ver=24

pkgname=grub-efi-x86_64
pkgver=2.00
pkgrel=1
pkgdesc="GNU GRand Unified Bootloader (2) - x86_64 UEFI Modules"
url="https://www.gnu.org/software/grub/"
arch=('any')
license=('GPL3')
makedepends=('xz' 'python' 'autogen' 'texinfo' 'help2man' 'gettext' 'device-mapper' 'fuse')
depends=("grub-common=${pkgver}" 'dosfstools' 'efibootmgr')

options=('!strip' '!emptydirs')
replaces=('grub2-efi-x86_64')
provides=('grub2-efi-x86_64')

source=("http://ftp.gnu.org/gnu/grub/grub-${pkgver}.tar.xz"
        "ftp://ftp.archlinux.org/other/grub2/grub2_extras_lua_r${_grub_lua_ver}.tar.xz")

noextract=("grub2_extras_lua_r${_grub_lua_ver}.tar.xz")

sha1sums=('274d91e96b56a5b9dd0a07accff69dbb6dfb596b'
          '89290031b974780c6df76893836d2477d4add895')

build() {

	if [[ "${CARCH}" == 'i686' ]]; then
		echo "This package can be built only in an x86_64 system. Exiting."
		exit 1
	fi

	cd "${srcdir}/grub-${pkgver}"

	## add grub-extras
	export GRUB_CONTRIB="${srcdir}/grub-${pkgver}/grub-extras/" 
	install -d "${srcdir}/grub-${pkgver}/grub-extras"

	bsdtar xf "${srcdir}/grub2_extras_lua_r${_grub_lua_ver}.tar.xz" \
		-C "${srcdir}/grub-${pkgver}/grub-extras"

	## start the actual build process
	cd "${srcdir}/grub-${pkgver}/"
	./autogen.sh

	CFLAGS="" ./configure \
		--with-platform="efi" \
		--target="x86_64" \
		--host="${CARCH}-unknown-linux-gnu" \
		--disable-efiemu \
		--enable-mm-debug \
		--enable-nls \
		--enable-device-mapper \
		--enable-cache-stats \
		--enable-grub-mkfont \
		--enable-grub-mount \
		--prefix="/usr" \
		--bindir="/usr/bin" \
		--sbindir="/usr/sbin" \
		--mandir="/usr/share/man" \
		--infodir="/usr/share/info" \
		--datarootdir="/usr/share" \
		--sysconfdir="/etc" \
		--program-prefix="" \
		--with-bootdir="/boot" \
		--with-grubdir="grub" \
		--disable-werror

	CFLAGS="" make

}

package() {

	cd "${srcdir}/grub-${pkgver}"
	make DESTDIR="${pkgdir}/" install 

	## remove non platform-specific files
	rm -rf "${pkgdir}"/{boot,etc,usr/{share,bin,sbin}}

	## remove gdb debugging related files
	rm -f "${pkgdir}/usr/lib/grub/x86_64-efi"/*.module || true
	rm -f "${pkgdir}/usr/lib/grub/x86_64-efi"/*.image || true
	rm -f "${pkgdir}/usr/lib/grub/x86_64-efi"/{kernel.exec,gdb_grub,gmodule.pl} || true

}
